package drds.binlog.binlog_event.event;

import drds.binlog.binlog_event.LogByteBlock;
import drds.binlog.binlog_event.LogEvent;
import drds.binlog.common.Authors;
import drds.common.Author;
import lombok.Getter;
import lombok.Setter;

/**
 * Logs xid of the transaction-to-be-committed in the 2pc protocol. Has no meaning in replication, slaves ignore it.
 */
@Author(name = Authors.LI_YANG)
public final class XidLogEvent extends LogEvent
{
    @Setter
    @Getter
    private final long xid;

    public XidLogEvent(LogHeader logHeader, LogByteBlock logByteBlock, FormatDescriptionLogEvent formatDescriptionLogEvent)
    {
        super(logHeader);
        /* The Post-Header is empty. The Variable Data part begins immediately. */
        logByteBlock.setIndexAsOriginIndexAndOffset(//
                formatDescriptionLogEvent.commonHeaderLength + formatDescriptionLogEvent.postHeaderLengths[xid_event - 1]);
        xid = logByteBlock.getLittleEndian8SignedLongByIndex(); //uint8
    }
}
